package com.atguigu.gulimall.order.web;

import com.atguigu.gulimall.order.alipay.AlipayTemplate;
import com.atguigu.gulimall.order.alipay.PayAsyncVo;
import com.atguigu.gulimall.order.alipay.PayVo;
import com.atguigu.gulimall.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author 满超
 * @date 2020/07/01
 **/
@RestController
public class AlipayController {

    @Autowired
    AlipayTemplate alipayTemplate;

    @Autowired
    OrderService orderService;


    @ResponseBody
    @GetMapping(value = "/payOrder",produces = "text/html")//告诉产生的数据类型
    public String payOrder(@RequestParam("orderSn") String orderSn) {

        PayVo vo = orderService.getOrderPay(orderSn);

        return alipayTemplate.pay(vo);
    }


    //支付成功后支付宝返回给我们的信息，如果不返回成功，支付宝会一直给我们发送消息
    @PostMapping("/alipay/success")
    public String handlePay(PayAsyncVo payAsyncVo){
        System.out.println("支付宝异步回调返回：" + payAsyncVo);

        return "success";//必须这个，表示已经接收
    }
}
